<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/pages/login/common.jsp"%>
<%
	String path = request.getContextPath();
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta content="B2B电商平台" name="description" />
<meta content="B2B电商平台" name="keyword" />

<title>B2B电商平台.店员权限设置</title>
<link rel="stylesheet" type="text/css" href="<%=path%>/include/css/btn.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/include/css/themes.css" />
<link rel="stylesheet" href="<%=path%>/include/JQuery zTree v3.4/css/zTreeStyle/zTreeStyle.css">
<link rel="stylesheet" type="text/css" href="<%=path%>/include/css/register_icss.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/include/css/page.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/include/pagination/page.css" media="all">
<link rel="stylesheet" href="<%=path%>/include/JQuery ui/css/smoothness/jquery-ui-1.7.3.custom.css" type="text/css"></link>
<link rel="stylesheet" type="text/css" href="<%=path%>/include/sweetalert/sweetalert.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/include/css/mmt_trading.css" />

<script type="text/javascript" src="<%=path%>/include/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="<%=path%>/include/JQuery ui/js/jquery-ui-1.7.3.custom.min.js"></script>
<script type="text/javascript" src="<%=path%>/include/js/icss.common.js"></script>
<script type="text/javascript" src="<%=path%>/include/js/cookies.js"></script>
<script type="text/javascript" src="<%=path%>/include/JQuery zTree v3.4/js/jquery.ztree.core-3.4.js"></script>
<script type="text/javascript" src="<%=path%>/include/JQuery zTree v3.4/js/jquery.ztree.excheck-3.4.js"></script>
<script type="text/javascript" src="<%=path%>/include/pagination/jquery.pagination.js"></script>
<script type="text/javascript" src="<%=path%>/include/pagination/init.js"></script>
<script type="text/javascript" src="<%=path%>/include/sweetalert/sweetalert.min.js"></script>
<script type="text/javascript" src="<%=path%>/include/sweetalert/sweetalert-dev.js"></script>

<style type="text/css">
#listTable td {
	font-size:12px;
    border-right: 1px solid #ddd;
    border-bottom:1px solid #ddd;
    padding: 4px;
}

.noborder {
	border: none;
	height: 2px;
	overflow: hidden;
}

.noborder td {
	height: 2px;
}

#listTable th {
	border-right: 1px solid #ddd;
	border-bottom:1px solid #ddd;
	font-weight: bold;
	font-size: 12px;
}
button{
    width:44px;
    height:24px;
    line-height:24px;   
    background-color: transparent;
    background-repeat: no-repeat;
    background-position: 0 -203px;
    border:0;
    cursor:pointer;
    font: 12px/1.5 arial,tahoma,\5b8b\4f53;
    margin: 0 0 0 5px;
    outline:none;
    background-image: url('<%=path%>/include/css/img/xs_bgx.png');   
}
</style>
<script type="text/javascript">
	$(function(){
		_queryList();
		zTree = $.fn.zTree.init($("#ztree"), treeSetting);
	})
	
	var pagination;
	function _queryList(){
		var url = "<%=path%>/authority/queryAccountList.do";
		var data = {
		};
		pagination = _initPagination({'pageId':'pagination', 'cKey':'authority','url': url,'data': data, 'rows': 8, 'callback':_initDataList});
	}
	
	function _initDataList(data) {
		var d = data.rows;
		var str = "";
		for(var i=0;i<d.length;i++){
			str += "<tr>";
			str += "	<td style='text-align:center;border-left:1px solid #ddd;'><input name='uuid' value='" + d[i].PERSON_ACCOUNT + "' type='radio' onclick='_showRes(\"" + d[i].PERSON_ACCOUNT + "\")'></td>";
			str += "	<td style='text-align:center;'>" + d[i].PID + "</td>";
			str += "	<td nowrap style='text-align:left;'>" + d[i].PERSON_ACCOUNT + "</td>";
			str += "	<td nowrap style='text-align:left;'>" + d[i].PERSON_NAME + "</td>";
			str += "	<td nowrap style='text-align:left;'>" + d[i].MOBILE + "</td>";
			str += "</tr>";
		}
		if(str == ''){
			str += "<tr>";
			str += "	<td colspan='5' style='text-align:center'>暂无数据</td>";
			str += "</tr>";
		}
		$("#list_tbody").html(str);
		_reHeight();
	}
	
	function _showRes(accountCode){
		$("#accountCode").val(accountCode);
		var zTree = $.fn.zTree.getZTreeObj("ztree");
		firstAsyncSuccessFlag = 0;
		zTree.reAsyncChildNodes(null, "refresh");
	}
	
	function _manage(){
		var checkFlag = false;
		var accountCode = '';
		var radioBox = document.getElementsByName("uuid");
		for(var j=0;j<radioBox.length; j++){
			checkFlag = radioBox[j].checked;
			if(checkFlag){
				accountCode = radioBox[j].value;
				j = radioBox.length;
			}
		}
		if(!checkFlag){
			alert("请选择店员账号！");
			return;
		}
		var treeObj = $.fn.zTree.getZTreeObj("ztree");
		var nodes = treeObj.getCheckedNodes(true);
		var nodeUuids = '';
		for(var i = 0; i< nodes.length; i++){
			var nodeId = nodes[i].id;
			var nodeName = nodes[i].name;
			var nodeUuid = nodes[i].uuid;
			nodeUuids += nodeUuid + ',';
		}
		if(nodeUuids != ''){
			nodeUuids = nodeUuids.substring(0,nodeUuids.length-1);
		}
	//	alert(nodeUuids);
		$.ajax({
			cache: true,
			type: "POST",
			url:'<%=path%>/authority/rigthUserManage.do',
			data:{
				uuid : nodeUuids,
				accountCode : accountCode
			},
			async: false,
			error: function(request) {
				alert('权限分配失败!');  
			},
			success: function(data) {
				data = eval('(' + data + ')');
				var msg = data.msg;
				if(data.success){
					alert(msg);
					location.reload();
				}else {
					alert(msg);
				}
			}
		});

	}
	
</script>
</head>
<body style="font-family: '微软雅黑';padding: 0px;">
	<input type="hidden" id="accountCode" name="accountCode">
	<div id="contentDiv" style="padding:5px; width:99%;">
		<div style="width:100%;height:30px;border-bottom:1px solid #ADADAD;margin-bottom: 15px;">
			<div class="toptil">店员权限设置</div>
		</div>
		<div style="padding-left:10px;height:40px;line-height:40px;font-size:14px;margin-left:2px;text-align:left;">
			<button  type="button" style="width:66px;background-size:180px 458px;margin-left:10px;" onclick="_manage(); return false;">分配权限</button>
		</div>
		<div class="row-fluid dataTables_wrapper" >
			<table style="width:100%;">
				<tr>
					<td style="width:70%;vertical-align:top;">
						<table id="listTable" class="table table-hover table-nomargin table-bordered usertable dataTable" style="width: 100%; border-spacing: 0;">
							<thead>
								<tr class="trBgd" style="background-color: #eee;text-align: center; height: 31px; border: 1px solid #ddd; white-space: nowrap; background-position: 0 -123px; line-height: 30px; font-weight: bold;">
									<th  nowrap style="border-top:1px solid #ddd;">选择</th>
									<th  nowrap style="border-top:1px solid #ddd;">序号</th>
									<th  nowrap style="border-top:1px solid #ddd;">店员账号</th>
									<th  nowrap style="border-top:1px solid #ddd;">店员名称</th>
									<th  nowrap style="border-top:1px solid #ddd;">联系方式</th>
								</tr>
							</thead>
							<tbody id="list_tbody" style="font-size: 13px">
							</tbody>
						</table>
						<div id="pagination"></div>
					</td>
					<td style="width:1%;">&nbsp;</td>
					<td style="width:25%;vertical-align:top;">
						<table id="listTable" class="table table-hover table-nomargin table-bordered usertable dataTable" style="width: 100%; border-spacing: 0;">
							<thead>
								<tr class="trBgd" style="background-color: #eee;text-align: center; height: 31px; border: 1px solid #ddd; white-space: nowrap; background-position: 0 -123px; line-height: 30px; font-weight: bold;">
									<th  nowrap style="border-top:1px solid #ddd;border-left:1px solid #ddd;">店铺资源</th>
								</tr>
							</thead>
							<tbody>
								<tr>
									<td style="border-left:1px solid #ddd;"> 
									<div style="height:360px;width:100%;overflow-x: hidden;overflow-y: auto;">
										<ul id="ztree" class="ztree" style="margin-top:0;"></ul>
									</div>
									</td>
								</tr>
							</tbody>
						</table>
					</td>
				</tr>
			</table>
			<div>
				<div style="height: 30px;"></div>
				<!-- 分类列表div结束 -->
				<div class="clear"></div>
			</div>
		</div>
	</div>

</body>
<script type="text/javascript">
	var zTree = null;
	/* 
	 * 下拉树的设置 
	 */  
	var treeSetting = {  
	    view: {  
	        dblClickExpand: false  
	    },  
		data: {  
			simpleData: {  
			    enable: true,
			    rootPId: 0
			}  
		},
		check: {  
			enable: true,
			autoCheckTrigger:true
		}, 
		
		async:{
			enable: true,//设置ztree是否开启异步加载模式
			showLine: true ,//设置是否显示连接线
			type: "post",//post方式请求数据
			url: getUrl,//数据请求url
			autoParam:["id","name"],//异步加载时需要自动提交父节点属性的参数
			otherParam:{"otherParam":"zTreeAsyncTest"},
			dataFilter: filter
		},
		callback:{
			beforeClick: beforeClick,
			onClick: deviceTypeOnClick,//点击节点
			onAsyncError : zTreeOnAsyncError,//加载失败
			onAsyncSuccess: zTreeOnAsyncSuccess//加载完成
		}
	}; 
	
	function getUrl(treeId, treeNode){
		var url = "<%=path %>/authority/getResourceTree.do?accountCode="+$("#accountCode").val();
		return url;
	}
	
	function beforeClick(treeId, treeNode) {
		var zTree = $.fn.zTree.getZTreeObj("ztree");
		zTree.checkNode(treeNode, !treeNode.checked, null, true);
		return false;
	}
	
	/* 
	 * 点击事件 
	 */  
	function deviceTypeOnClick(e, treeId, treeNode) {  
	    var zTree = $.fn.zTree.getZTreeObj("ztree");  
	    nodes = zTree.getSelectedNodes();  
	    treeNode = nodes[0];
//	    if(treeNode.isParent){//判断是否是父节点
				
//		}else{

//		}
	}  
	//过滤函数  
    function filter(treeId, parentNode, childNodes) {  
        if (!childNodes)  
            return null;  
        for ( var i = 0, l = childNodes.length; i < l; i++) {  
            //childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');  
        }  
        return childNodes;  
    }  
    //加载完成
	var firstAsyncSuccessFlag = 0;
	function zTreeOnAsyncSuccess(event, treeId, msg) {  
		if (firstAsyncSuccessFlag == 0) {  
        	try {
				//调用默认展开第一个结点
//				var nodes = zTree.getNodes();
//			//	zTree.expandNode(nodes[0], true);
//				for(var i = 0; i< nodes.length; i++){
//					zTree.expandNode(nodes[i], true);
//				}
//				$("#tree_1_a").click();
	            
				//异步加载完成再折叠所有子节点
	            var nodes = zTree.getNodes();
				if (nodes.length>0) {
					var index = zTree.getNodeIndex(nodes[0]);
					for(var j=0; j<nodes.length; j++){
						var rootNode = nodes[j];
						zTree.expandNode(rootNode, false, true, null, true);
					}
				}
	            firstAsyncSuccessFlag = 1;
        	} catch (err) {
	              
         	}
    	}
	}
	//加载失败提示  
    function zTreeOnAsyncError(event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) {  
        alert("加载错误：" + XMLHttpRequest);  
    };

	$(document).ready(function() {
		_reHeight();
	});
	function _reHeight() {
		var main = $(window.parent.document).find("#rightFrame");
		var mainheight = $("#contentDiv").height();
		main.height(mainheight);
	}
	
	
</script>
</html>